package org.monkey.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.monkey.service.OrderService;
import org.monkey.service.User;
import org.monkey.service.UserService;
import org.monkey.spring.*;

@Slf4j
@Component("userService")
@Scope()
public class UserServiceImpl implements BeanNameAware, UserService,  InitializingBean {

    @Autowired
    private OrderService orderService;

    private String beanName;

    private String name;

    private User defaultUser;

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void test() {
        log.info("orderService: {}",orderService);
        log.info("beanName: {}",beanName);
        log.info("name: {}",name);
        log.info("default user {}", defaultUser);
    }

    /**
     * 获取bean名称
     * @param name
     */
    @Override
    public void setBeanName(String name) {
        beanName = name;
    }

    public String getBeanName() {
        return beanName;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("init...");
        defaultUser = new User();
    }

    public User getDefaultUser() {
        return defaultUser;
    }

    public void orderService() {
        System.out.println("UserServiceImpl orderService");
        orderService.orderService();
    }
}
